<?php

namespace app\user\controller;

use app\admin\model\Domain;
use app\common\controller\Api;
use app\common\model\Order as OrderModel;
use app\common\model\Store as StoreModel;
use app\common\model\StoreProject;
use think\Exception;
use think\Request;

/**
 * 门店接口
 */
class Store extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    //区域列表
    public function area()
    {

        $list = Domain::order('createtime desc')->select();
        $this->success('',$list);
    }

    /**
     * 门店列表
     *
     */
    public function lists()
    {
        /*$request = Request::instance();
        $domain = $request->domain();
        $result = parse_url($domain);
        $host = $result['host'];
        $domain_info = Domain::get(['name'=>$host]);*/

        $id = input('id',0);
        $where = ['status'=>'normal'];
        if ($id){
            $where['domain_id'] = $id;
        }
        /*if ($domain_info){
            $where['domain_id'] = $domain_info['id'];
        }*/
        $list = StoreModel::where($where)
            ->field('store_id,store_name,mobile,address')
            ->order('weigh desc')->select();
        $this->success('请求成功',$list);
    }

    //门店资料
    public function info()
    {
        $store_id = input('store_id','');
        if (empty($store_id)){
            $this->error('缺少参数门店id');
        }

        $info = StoreModel::get($store_id);
        $this->success('请求成功',$info);
    }

    //项目列表
    public function project()
    {
        $store_id = input('store_id',0);

        $list = StoreProject::where(['store_id'=>$store_id])->select();


        $this->success('请求成功',$list);
    }


}
